/*
 * Java Card File Parser 
 * Based on openjcvm project 
 */
package org.naive.metawatch.converter;

import java.io.*;
import java.text.ParseException;
import org.naive.metawatch.converter.exp.ExpInfo;
import org.naive.metawatch.converter.parser.ParseContext;

/**
 *
 * @author Andrew Butenko
 */
public class MetawatchConverter {

    /**
     * @param args the command line arguments
     */
    private static byte[] readAll(InputStream is) throws IOException {
        final ByteArrayOutputStream bos = new ByteArrayOutputStream();
        try {
            byte[] kilo = new byte[1024];
            int read = 0;
            while ((read = is.read(kilo)) > 0) {
                bos.write(kilo, 0, read);
            }
        } finally {
            if (is != null) {
                is.close();
            }
            bos.close();
        }
        return bos.toByteArray();
    }
   
    private static byte[] readFile(String fileName) throws IOException {
        InputStream is = null;
        try {
            is = new FileInputStream(fileName);
            return readAll(is);
        } finally {
            if (is != null) {
                is.close();
            }
        }
   }
   
    
   
    public static void main(String[] args) throws IOException, ParseException {
//        final ParseContext px = new ParseContext(readFile(args[0]));
//        final ExpInfo expFile = new ExpInfo();
//        expFile.parse(px);
//
//        System.out.println(expFile);
        CapParser p = new CapParser();
        p.readCap(args[0]);
        ExpInfo e = new ExpInfo();
        
        e.parse(new ParseContext(readFile(args[1])));
        System.out.print(e);
    }

}
